package com.qimou.iems.service.impl;

import com.qimou.iems.entity.PageArgs;
import com.qimou.iems.entity.PageList;
import com.qimou.iems.entity.QualityCategoryChild;
import com.qimou.iems.mapper.IQualityCategoryChildMapper;
import com.qimou.iems.service.IQualityCategoryChildService;
import com.qimou.iems.util.CommonUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Qimou Xie
 * @date 2018/6/9 10:49.
 **/

@Service
public class QualityCategoryChildServiceImpl implements IQualityCategoryChildService {


    @Resource
    private IQualityCategoryChildMapper qualityCategoryChildMapper;


    @Override
    public QualityCategoryChild findById(Integer id) {
        return qualityCategoryChildMapper.selectById(id);
    }

    @Override
    public List<QualityCategoryChild> getChildList(Integer categoryId, String childName) {
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("childName", CommonUtil.isEmpty(childName) ? null : childName);
        map.put("categoryId", CommonUtil.isEmpty(categoryId) ? null : categoryId);
        map.put("pageArgs", null);
        return qualityCategoryChildMapper.selectChild(map);
    }

    @Override
    public void save(QualityCategoryChild categoryChild) {
        qualityCategoryChildMapper.insert(categoryChild);
    }

    @Override
    public void update(QualityCategoryChild categoryChild) {
        qualityCategoryChildMapper.update(categoryChild);
    }

    @Override
    public PageList<QualityCategoryChild> getList(Map<String, Object> map, PageArgs pageArgs) {
        List<QualityCategoryChild> qualityCategoryChildren = new ArrayList<QualityCategoryChild>();
        Integer count = qualityCategoryChildMapper.countChild(map);
        if(null != count && count > 0){
            map.put("pageArgs",pageArgs);
            qualityCategoryChildren = qualityCategoryChildMapper.selectChild(map);
        }
        return new PageList<QualityCategoryChild>(qualityCategoryChildren,count);
    }
}
